home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
xinu.arc
/
XINU.H
< prev
next >
Wrap
Text File
|
1986-01-03
|
26KB
|
656 lines
/* bufpool.h p. 234 */
# ifndef NBPOOLS
# define NBPOOLS 5 /* maximum number of pools */
# endif
# ifndef BPMAXB
# define BPMAXB 512 /* maximum buffer length */
# endif
# define BPMINB 2 /* minimum buffer length */
# ifndef BPMAXN
# define BPMAXN 100 /* maximum buffers in any pool */
# endif
struct bpool { /* description of a single pool */
int bpsize; /* size of buffers in this pool */
char *bpnext; /* pointer to next free buffer */
int bpsem; /* semaphore that counts buffers */
}; /* currently in THIS pool */
extern struct bpool bptab[]; /* buffer pool table */
extern int nbpools; /* current number of pools */
# ifdef MEMMARK
extern MARKER bpmark;
# endif
/* conf.h p. 142 */
# define NULLPTR (char *)0
/* device table declarations */
struct devsw { /* device table entry */
int dvnum;
int (*dvinit)();
int (*dvopen)();
int (*dvclose)();
int (*dvread)();
int (*dvwrite)();
int (*dvseek)();
int (*dvgetc)();
int (*dvputc)();
int (*dvcntl)();
int dvcsr;
int dvivec;
int dvovec;
int (*dviint)();
int (*dvoint)();
char *dvioblk;
int dvminor;
};
extern struct devsw devtab[]; /* one entry per device */
/* device name definitions */
# define CONSOLE 0 /* type tty */
# define OTHER 1 /* type tty */
# define DISK0 2 /* type dsk */
# define FILE1 3 /* type df */
# define FILE2 4 /* type df */
# define FILE3 5 /* type df */
# define FILE4 6 /* type df */
# define MEM 7 /* type mem */
/* Control block sizes */
# define Ntty 2
# define Ndsk 1
# define Ndf 4
# define Nmem 1
è# define NDEVS 8
/* declarations of I/O routines referrenced */
extern int ttyinit();
extern int ionull();
extern int ttyread();
extern int ttywrite();
extern int ioerr();
extern int ttycntl();
extern int ttygetc();
extern int ttyputc();
extern int ttyiin();
extern int ttyoin();
extern int dsinit();
extern int dsopen();
extern int dsread();
extern int dswrite();
extern int dsseek();
extern int dscntl();
extern int dsinter();
extern int lfinit();
extern int lfclose();
extern int lfread();
extern int lfwrite();
extern int lfseek();
extern int lfgetc();
extern int lfputc();
extern int memread();
extern int memwrite();
/* Configuration and Size Constants */
# define MEMMARK /* define if memory marking used */
# define NPROC 10 /* number of user processes */
# define NSEM 50 /* total number of semaphores */
# define RTCLOCK /* system has a real-time clock */
# define VERSION "X.XX (11/9/84)"
/* message printed at startup */
/* dir.h p. 318 */
# define FDNLEN 10 /* length of file name + 1 */
# define NFDES 28 /* number of files per directory */
struct fdes { /* description of each file */
long fdlen; /* length in bytes */
IBADDR fdiba; /* first index block */
char fdname[FDNLEN]; /* null-terminated file name */
};
struct dir { /* directory layout */
int d_iblks; /* i-blocks on this disk */
DBADDR d_fblst; /* pointer to list of free blocks */
IBADDR d_filst; /* pointer to list of free i-blocks */
int d_id; /* disk identification integer */
int d_nfiles; /* current number of files */
struct fdes d_files[NFDES]; /* descriptions of the files */
};
struct freeblk { /* shape of block on free list */
DBADDR fbnext; /* address of next free block */
};
/* disk.h - dssync, dsdirec p. 285 */
# include <xebec.h> /* disk controller constants */
# include <dtc.h> /* disk interface constants */
typedef unsigned int DBADDR; /* disk data block addresses */
# define DBNULL (DBADDR)0177777 /* null disk block address */
struct dsblk { /* disk driver control block */
struct dtc *dcsr; /* disk interface csr address */
struct dreq *dreqlst; /* list of pending requests */
int dnum; /* device number of this disk */
int dibsem; /* i-block mutual exclusion semaphore*/
int dflsem; /* free list mutual exclusion semaph */
int ddirsem; /* directory mutual exclusion semaph */
int dnfiles; /* number of currently open files */
char *ddir; /* address of in-core directory */
struct xbdcb ddcb; /* hold commands that interface sends*/
}; /* to disk controller */
extern struct dsblk dstab[];
struct dreq { /* node in list of requests */
DBADDR drdba; /* disk block address to use */
int drpid; /* process id making request */
char *drbuff; /* buffer address for read / write */
char drop; /* operation: READ / WRITE / SEEK */
int drstat; /* returned status OK / SYSERR */
struct dreq *drnext; /* ptr to next node on request list */
};
# define DRNULL (struct dreq *)0 /* null pointer in request list */
# define DIRBLK 0 /* block used to hold directory */
# define DONQ 2 /* status if request enqueued */
# define DBUFSIZ 512 /* size of disk data block */
# define DREQSIZ sizeof(struct dreq) /* size of disk request node */
# ifndef NDBUFF
# define NDBUFF 10 /* number fo disk data buffers */
# endif
# define NDREQ 10 /* number of disk request buffers */
# define DREAD XOREAD /* read command in dreq.drop */
# define DWRITE XOWRITE /* write command in dreq.drop */
# define DSEEK XOSEEK /* seek command in dreq.drop */
# define DSYNC XOTDR /* sync command in dreq.drop */
extern int dskrbp; /* disk request node buffer pool */
extern int dskdbp; /* disk data block buffer pool */
/* disk control function codes */
# define DSKSYNC 0 /* synchronize ( flush all I/O ) */
# define dssync(ddev) control((ddev),DSKSYNC);
# define dsdirec(ddev) ((struct dir *)devtab[ddev].dvioblk->ddir)
/* dtc.h p. 284 */
/* Digital Technology Corp. DTC-11-1 disk controller host interface */
struct dtc { /* controller interface registers */
int dt_ccsr; /* command completion status */
int dt_csr; /* control and status register */
char *dt_dar; /* data address register */
struct xbdcb *dt_car; /* command address register */
int dt_xdar; /* extension of dar (not used) */
int dt_xcar; /* extension of car (not used) */
};
/* bits in the dtc csr register */
# define DTGO 0000001 /* "go" bit - start interface */
# define DTRESET 0000002 /* "force reset" bit */
# define DTINTR 0000100 /* enable interface interrupt */
# define DTDONE 0000200 /* command done */
# define DTERROR 0100000 /* some error occurred */
/* file.h p. 320 */
/* Local disk layout: disk block 0 is directory, then index area, and then *
* data blocks. Each disk block (512 bytes) in the index area contains 8 *
* i-blocks, which are 64 bytes long. Iblocks are referenced relative to 0 *
* so the disk block address of iblock k is given by truncate(k/8)+1. The *
* offset of iblock k within its disk block is given by 64*remainder(k,8). *
* The directory entry points to a linked list of iblocks, and each iblock *
* contains pointers to IBLEN (29) data blocks. Index pointers contain a *
* valid data block address of DBNULL. */
# include <iblock.h>
# define EOF -2 /* value returned on end-of-file */
# define FLREAD 001 /* fl_mode bit for "read" */
# define FLWRITE 002 /* fl_mode bit for "write" */
# define FLRW 003 /* fl_mode bits for read+write */
# define FLNEW 010 /* fl_mode bit for "new file" */
# define FLOLD 020 /* fl_mode bit for "old file" */
struct flblk { /* file "device" control block */
int fl_id; /* file's "device id" in devtab */
int fl_dev; /* file is on this disk device */
int fl_pid; /* process id accessing the file */
struct fdes *fl_dent; /* file's in-core directory entry */
int fl_mode; /* read, write, or both */
IBADDR fl_iba; /* address of iblock in fl_iblk */
struct iblk fl_iblk; /* current iblock for file */
int fl_ipnum; /* current iptr in fl_iblk */
long fl_pos; /* current file position (bytes) */
Bool fl_dch; /* has fl_buff been changed ? */
char *fl_bptr; /* ptr to next character in fl_buff */
char fl_buff[DBUFSIZ]; /* current data block for file */
};
# ifdef Ndf
extern struct flblk fltab[];
# endif
/* iblock.h - ibtodb, ibdisp p. 310 */
typedef int IBADDR; /* iblocks addressed 0, 1, 2, ... */
# define IBLEN 29 /* # d-block pointers in an i-block */
# define IBNULL -1 /* null pointer in i-block list */
# define IBAREA 1 /* start if iblocks on disk */
# define IBWDIR TRUE /* ibnew: write directory */
# define IBNWDIR FALSE /* ibnew: don't write directory */
struct iblk { /* index block layout */
long ib_byte; /* 1st d-byte indexed by this iblock */
IBADDR ib_next; /* address of next i-block */
DBADDR ib_dba[IBLEN]; /* pointers to data blocks indexed */
};
# define ibtodb(ib) (((ib)>>3)+IBAREA)/*iblock to disk block addr*/
# define ibdisp(ib) (((ib)&07)*sizeof(struct iblk))
/* io.h - fgetc, fputc, getchar, isbaddev, putchar p. 116 */
#define INTVECI inint /* input interrupt dispatch routine */
#define INTVECO outint /* output interrupt dispatch routine */
extern int INTVECI();
extern int INTVECO();
struct intmap { /* device-to-interrupt routine mapping */
int (*iin)(); /* address of input interrupt routine */
int icode; /* argument passed to input routine */
int (*iout)(); /* address of output interrupt routine */
int ocode; /* argument passed to output routine */
};
#ifdef NDEVS
extern struct intmap intmap[NDEVS];
#define isbaddev(f) ((f)<0 || (f)>=NDEVS)
#endif
/* In-line I/O procedures */
#define getchar() getc(CONSOLE)
#define putchar(ch) putc(CONSOLE,(ch))
#define fgetc(unit) getc((unit))
#define fputc(unit,ch) putc((unit),(ch))
struct vector {
char *vproc; /* address of interrupt procedure */
int vps; /* saved process status word */
};
/* kernel.h - disable, enable, halt, restore, isodd p. 72 */
/* Symbolic constants used throughout Xinu */
#define Bool char /* Boolean type */
#define FALSE 0 /* Boolean constants */
#define TRUE 1
#define NULL (char *)0 /* Null pointer for linked lists */
#define SYSCALL int /* System call declaration */
#define LOCAL static /* Local procedure declarations */
#define INTPROC int /* Interrupt procedure declaration */
#define PROCESS int /* Process declaration */
#define RESCHYES 1 /* tell ready to reschedule */
#define RESCHNO 0 /* tell ready not to reschedule */
#define MININT 0100000 /* minimum integer (-32768) */
#define MAXINT 0077777 /* maximum integer (32767) */
#define SP 6 /* register 6 is stack pointer */
#define PC 7 /* register 7 is program counter */
#define PS 8 /* register 8 is processor status */
#define MINSTK 40 /* minimum process stack size */
#define NULLSTK 300 /* process 0 stack size */
#define DISABLE 0340 /* PS to disable interrupts */
#define OK 1 /* returned when system call ok */
#define SYSERR -1 /* returned when system call fails */
/* initialization constants */
#define INITARGC 1 /* initial process argc */
#define INITSTK 200 /* initial process stack */
#define INITPRIO 20 /* initial process priority */
#define INITNAME "main" /* initial process name */
#define INITRET userret /* processes return address */
#define INITPS 0 /* initial process PS */
#define INITREG 0 /* initial register contents */
#define QUANTUM 10 /* clocks ticks until preemption */
/* misc. utility inline functions */
#define isodd(x) (01&(int)(x))
#define disable(ps) asm("mfps ~ps");asm("mtps $0340")
#define restore(ps) asm("mtps ~ps") /* restore interrupt status */
#define enable() asm("mtps $000")/* enable interrupts */
#define pause() asm("wait") /* machine "wait for interr."*/
#define halt() asm("halt") /* machine halt instruction */
extern int rdyhead, rdytail;
extern int preempt;
/* mark.h - unmarked p. 232 */
# ifndef MAXMARK
# define MAXMARK 20 /* maximum number of marked locations*/
# endif
# ifdef MEMMARK
extern int *(marks[]);
extern int nmarks;
extern int mkmutex;
typedef int MARKER[1]; /* by declaring it to be an array, */
/* the name provides an address so */
/* forgotten &'s don't become a prob.*/
# define unmarked(L) (L[0]<0 || L[0]>=nmarks || marks[L[0]]!=L)
# endif
/* mem.h - freestk, roundew, truncew p. 105 */
/*-----------------------------------------------------------------------------
* roundew, truncew - round or truncate address to next even word
*-----------------------------------------------------------------------------
*/
# define roundew(x) (int *)((3 + (int)(x)) & (~3))
# define truncew(x) (int *)(((int)(x)) & (~3))
/*-----------------------------------------------------------------------------
* freestk -- free stack memory allocated by getstk
*-----------------------------------------------------------------------------
*/
# define freestk(p,len) freemem((unsigned)(p) \
- (unsigned)(roundew(len)) \
+ (unsigned)sizeof(int), \
roundew(len))
struct mblock {
struct mblock *mnext;
unsigned int mlen;
};
extern struct mblock memlist; /* head of free memory list */
extern int *maxaddr; /* max memory address */
extern int end; /* address beyond loaded memory */
/* ports.h - isbadport p. 242 */
# define NPORTS 30 /* maximum number of ports */
# define MAXMSGS 100 /* maximum messages on all ports */
# define PTFREE '\01' /* port is free */
# define PTLIMBO '\02' /* port is being deleted/reset */
# define PTALLOC '\03' /* port is allocated */
# define PTEMPTY -1 /* initial semaphore entries */
struct ptnode { /* node on list of message pointers */
int ptmsg; /* a one-word message */
int *ptnext; /* address of next node on list */
};
struct pt { /* entry in the port table */
char ptstate; /* port state FREE/LIMBO/ALLOCATED */
int ptssem; /* sender semaphore */
int ptrsem; /* receiver semaphore */
int ptmaxcnt; /* max messages to be queued */
int ptseq; /* sequence changed at creation */
struct ptnode *pthead; /* list of message pointers */
struct ptnode *pttail; /* tail of message list */
};
extern struct ptnode *ptfree; /* list of free nodes */
extern struct pt ports[]; /* port table */
extern int ptnextp; /* next port to examine when looking */
/* for a free one */
# ifdef MEMMARK
extern MARKER ptmark;
# endif
# define isbadport(pid) ((pid)<0 || (pid)>=NPORTS)
/* proc.h - isbadpid p. 54 */
/* process table declarations and defined constants */
# ifndef NPROC
# define NPROC 10 /* set the number of processes */
# endif /* allowed if not already done */
/* process state constants */
# define PRCURR '\01' /* process is currently running */
# define PRFREE '\02' /* process slot is free */
# define PRREADY '\03' /* process is on ready queue */
# define PRRECV '\04' /* process waiting for message */
# define PRSLEEP '\05' /* process is sleeping */
# define PRSUSP '\06' /* process is suspended */
# define PRWAIT '\07' /* process is on semaphore queue */
/* miscellaneous process definitions */
# define PNREGS 9 /* size of saved register area */
# define PNMLEN 8 /* length of process "name" */
# define NULLPROC 0 /* id of the null process; it is */
/* always eligible to run */
# define isbadpid(x) (x<=0 || x>=NPROC)
/* process table entry */
struct pentry {
char pstate; /* process state: PRCURR, etc. */
short pprio; /* process priority */
short pregs[PNREGS]; /* saved regs. R0-R5, SP, PC, PS */
short psem; /* semaphore if process waiting */
short pmsg; /* message sent to this process */
short phasmsg; /* nonzero iff pmsg is valid */
short pbase; /* base of run time stack */
short pstklen; /* stack length */
short plimit; /* lowest extent of stack */
char pname[PNMLEN]; /* process name */
short pargs; /* initial number of arguments */
short paddr; /* initial code address */
};
extern struct pentry proctab[];
extern int numproc; /* currently active processes */
extern int nextproc; /* search point for free slot */
extern int currpid; /* currently executing process */
/* q.h - firstid, firstkey, isempty, lastkey, nonempty p. 44 */
/* q structure declarations, constants, and inline procedures */
# ifndef NQENT
# define NQENT NPROC + NSEM + NSEM + 4 /* for ready & sleep */
# endif
struct qent { /* one for each process plus two for */
/* each list */
short qkey; /* key on which the queue is ordered */
short qnext; /* pointer to next process or tail */
short qprev; /* pointer to previous process or head */
};
extern struct qent q[];
extern int nextqueue;
/* inline list manipulation procedures */
# define isempty(list) (q[(list)].qnext >= NPROC)
# define nonempty(list) (q[(list)].qnext < NPROC)
# define firstkey(list) (q[q[(list)].qnext].qkey)
# define lastkey(tail) (q[q[(tail)].qprev].qkey)
# define firstid(list) (q[(list)].qnext)
# define EMPTY -1 /* equivalent of null pointer */
/* sem.h - isbadsem p. 84 */
# ifndef NSEM
# define NSEM 45 /* number of semaphores, if not defined */
# endif
# define SFREE '\01' /* this semaphore is free */
# define SUSED '\02' /* this semaphore is used */
struct sentry { /* semaphore table entry */
char sstate; /* the state SFREE or SUSED */
short semcnt; /* count for this semaphore */
short sqhead; /* q index of head of list */
short sqtail; /* q index of tail of list */
};
extern struct sentry semaph[];
extern int nextsem;
# define isbadsem(s) (s<0 || s>=NSEM)
/* sleep.h p. 130 */
# define CVECTOR 0100 /* location of clock interrupt vector */
extern int clkruns; /* 1 iff clock exists; 0 otherwise */
/* Set at system startup. */
extern int clockq; /* q index of sleepin process list */
extern int count6; /* used to ignore 5 of 6 interrupts */
extern int *sltop; /* address of first key on clockq */
extern int slnempty; /* 1 iff clockq is nonempty */
extern int defclk; /* >0 iff clock interrupts are deferred */
extern int clkdiff; /* number of clock clicks deferred */
extern int clkint(); /* clock interrupt handler */
/* slu.h p. 168 */
/* standart serial line unit device constants */
# define SLUENABLE 0100 /* device interrupt enable bit */
# define SLUREADY 0200 /* device ready bit */
# define SLUDISABLE 0000 /* device interrupt disable mask */
# define SLUTBREAK 0001 /* transmitter break-mode bit */
# define SLUERMASK 0170000 /* mask for error flags on input */
# define SLUCHMASK 0377 /* mask for input character */
/* SLU device register layout and correspondence to vendor's names */
struct csr {
int crstat; /* receiver control and status (RCSR) */
int crbuf; /* receiver data buffer (RBUF) */
int ctstat; /* transmitter control and status (XCSR) */
int ctbuf; /* transmitter data buffer (XBUF) */
};
/* tty.h p. 161 */
# define IOCHERR 0200 /* bit set on when an error */
/* occurred readint the character */
# define OBMINSP 20 /* minimum space in buffer before */
/* processes awakened to write */
# define EBUFLEN 20 /* size of echo queue */
/* size constants */
# ifndef Ntty
# define Ntty 1 /* number of serial tty lines */
# endif
# ifndef IBUFLEN
# define IBUFLEN 128 /* number of chars in input queue */
# endif
# ifndef OBUFLEN
# define OBUFLEN 64 /* number of chars in output queue */
# endif
/* mode constants */
# define IMRAW 'R' /* raw mode => nothing done */
# define IMCOOKED 'C' /* cooked mode => line editing */
# define IMCBREAK 'K' /* honor echo, etc., no line editing */
# define OMRAW 'R' /* raw mode => normal processing */
struct tty { /* tty line control block */
int ihead; /* head of input queue */
int itail; /* tail of input queue */
char ibuff[IBUFLEN]; /* input bruffer for this line */
int isem; /* input semaphore */
int ohead; /* head of output queue */
int otail; /* tail of output queue */
char obuff[OBUFLEN]; /* output bruffer for this line */
int osem; /* output semaphore */
int odsend; /* sends delayed for space */
int ehead; /* head of echo queue */
int etail; /* tail of echo queue */
char ebuff[EBUFLEN]; /* echo queue */
char imode; /* IMRAW, IMCBREAK, IMCOOKED */
Bool iecho; /* is input echoed? */
Bool ieback; /* do erasing backspace on echo? */
Bool evis; /* echo control characters as ^X ? */
Bool ecrlf; /* echo CR-LF for newline? */
Bool icrlf; /* map '\r' to '\n' on input? */
Bool ierase; /* honor erase character? */
char ierasec; /* erase character (backspace) */
Bool ikill; /* honor line kill character? */
char ikillc; /* line kill character */
int icursor; /* current cursor position */
Bool oflow; /* honor ostop/ostart? */
Bool oheld; /* output currently being held? */
char ostop; /* character that stops output */
char ostart; /* character that restarts output */
Bool ocrlf; /* echo CR/LF for LF ? */
char ifullc; /* char to send when input full */
struct csr *ioaddr; /* device address of this unit */
};
extern struct tty tty[];
# define BACKSP '\b'
# define BELL '\07'
# define ATSIGN '@'
# define BLANK ' '
# define NEWLINE '\n'
# define RETURN '\r'
# define STOPCH '\023' /* control-S stops output */
# define STRTCH '\021' /* control-Q restarts output */
# define UPARROW '^'
/* ttycontrol function codes */
# define TCSETBRK 1 /* turn on BREAK in transmitter */
# define TCRSTBRK 2 /* turn off BREAK in transmitter */
# define TCNEXTC 3 /* look ahead 1 character */
# define TCMODER 4 /* set input mode to raw */
# define TCMODEC 5 /* set input mode to cooked */
# define TCMODEK 6 /* set input mode to cbreak */
# define TCICHARS 8 /* return number of input chars */
# define TCECHO 9 /* turn on echo */
# define TCNOECHO 10 /* turn off echo */
# define TFULLC BELL /* char to echo when buffer is full */
/* xebec.h p. 282 */
/* Xebec S1410 5.25 inch Winchester Disk Controller */
struct xbdcb { /* Xebec disk controller registers */
char xop; /* command calss/opcode */
char xunit; /* unit/high-order address bits */
char xmaddr; /* middle-order address bits */
char xladdr; /* low-order address bits */
char xcount; /* block count */
char xcntl; /* control field */
char xres1; /* reserved field #1 */
char xres2; /* reserved field #2 */
};
/* Xebec controller operation codes */
# define XOTDR 0 /* test drive ready */
# define XORCAL 1 /* recalibrate */
# define XORSS 3 /* request sense status */
# define XOFMTD 4 /* format drive */
# define XOCTF 5 /* check track format */
# define XOFMTT 6 /* format track */
# define XOFMTBT 7 /* format bad track */
# define XOREAD 8 /* read */
# define XOWRITE 10 /* write */
# define XOSEEK 11 /* seek */
# define XOINIT 12 /* initialize drive character. */
# define XOREBEL 13 /* read ECC burst error length */
# define XORAMD 14 /* perform RAM diagnostic test */
# define XRETRY 0 /* retry control byte */